package sfsoftware.game.actor.enemy;

import sfsoftware.game.actor.attributes.Poisonable;
import sfsoftware.game.trevor.Enemy;
import sfsoftware.util.Tile;
import sfsoftware.util.Updatable;

public class RenegadeSquirrel extends Enemy implements Updatable, Poisonable 
{
	protected boolean isCloaked = false;
	protected boolean isPoisoned = false;	
	protected float alpha = 1;
	
	public RenegadeSquirrel(int destX, int destY, String texture, int destWidth, int destHeight, Tile[][] assocTileMap)
	{
		super(destX, destY, texture, 0, 0, destWidth, destHeight);	

		tileMap = assocTileMap;	
		health = 3;
		maxHealth = 3;
		
		setSpeed(3);
	}

	public void draw()
	{
		if(!isPoisoned)
		{	
			super.draw(width, height, getSrcX(), getSrcY(), width, height, 1, 1, 1, alpha);
		}
		else
		{
			super.draw(width, height, getSrcX(), getSrcY(), width, height, 0, 1, 0, 1);
		}
	}
	
	public void setPoisoned(boolean p)
	{
		isPoisoned = p;
		// Being poisoned causes a character to move at half speed.
		if(isPoisoned)
		{
			speed = speed / 2;
		}
		else
		{
			speed = speed * 2;
		}
	}
	
	public void togglePoisoned()
	{		
		if(isPoisoned)
		{
			setPoisoned(false);
		}
		// Renegade squirrels can only be poisoned when they aren't cloaked.
		else if(!(isCloaked))
		{
			setPoisoned(true);
		}
	}	
	
	@Override
	public void update() {
		
		// Handle fading in and out if the renegade squirrel is cloaked.
		if(isCloaked)
		{
			// Fade out
			if(alpha > 0.2f)
			{
				alpha = alpha + 0.01f;
			}
			else
			{
				alpha = 0.2f;
			}				
		}
		else
		{
			// Fade in
			if(alpha < 1)
			{
				alpha = alpha + 0.025f;
			}
			else
			{
				alpha = 1;
			}
		}
		
	}
	
	@Override
	public void wiffaHit() 
	{
		// Hits from the wiffa are only effective if the squirrel is uncloaked!
		if(!(isCloaked))
		{
			super.wiffaHit();
		}
	}
}
